#include "document.h"
#include "project.h"
#include "word.h"

using namespace TA;

Document::Document(QObject *parent) : QObject(parent)
{
   init(parent,QString(""));
}

Document:: Document(QObject *parent,const QString& uuid):QObject(parent){
    init(parent,uuid);
}

QString Document::getUuid() const
{
    return uuid;
}

void Document::setUuid(const QString &value)
{
    uuid = value;
}

QString Document::getTitle() const
{
    return title;
}

void Document::setTitle(const QString &value)
{
    title = value;
}

QString Document::getContent() const
{
    return content;
}

void Document::setContent(const QString &value)
{
    content = value;
}

Project *Document::getProject() const
{
    return project;
}

void Document::setProject(Project *value)
{
    project = value;
}

bool Document::operator==(const Document &rhs)
{
    return this->title == rhs.title && this->project == rhs.project;
}

bool Document::operator<(const Document &rhs)
{
    return this->title < rhs.title;
}

void Document::init(QObject *parent, const QString &uuid)
{
    Project* project = qobject_cast<Project*>(parent);
    if(project){
        this->project = project;
    }

    if(!uuid.isEmpty()){
        this->uuid = uuid;
    }
}

WordRawPtrArray *Document::getWords() {
    return &words;
}

QDate Document::getCreateDate() const {
    return createDate;
}

void Document::setCreateDate(const QDate &createDate) {
    Document::createDate = createDate;
}

int Document::getUnCheckedCount() {
    int result = 0;
    for (auto it = words.begin(); it != words.end() ; ++it) {
        if ((*it)->getStatus() == UNCHECKED){
            result++;
        }
    }
    return result;
}

int Document::getCheckedCount() {
    int result = 0;
    for (auto it = words.begin(); it != words.end() ; ++it) {
        if ((*it)->getStatus() > UNCHECKED){
            result++;
        }
    }
    return result;
}


 WordRawPtr Document::getWord(const QString& word){
     return nullptr;
 }


